
import { DecimalCalculator as calc } from "./math"

export const getFBA = (dataForm: any) => {

    const { zhongOz, zhongP, dingjia1, chang2, kuan2, gao2, tijizhong1, } = dataForm

    const priceLevel = dingjia1 < 10 ? 0 : dingjia1 > 50 ? 2 : 1

    const size = chang2 + kuan2 + gao2 <= 130
        && Math.max(chang2, kuan2, gao2) <= 60
        && Math.max(zhongP, tijizhong1) < 1 ? '小号标准件' : '大号标准件'

    const nowTime = Date.now()
    const year = new Date().getFullYear()
    const startTime = new Date(`${year}-1-15 0:0:0`).getTime()
    const endTime = new Date(`${year}-10-15 23:59:59`).getTime()
    // 非旺季
    const isFWj = startTime < nowTime && nowTime < endTime

    function getPrice() {
        if (isFWj) {
            // 2026年1月15日起 非旺季
            if (size === '小号标准件') {
                // 小号标准件
                if (zhongOz <= 2) {
                    return [2.43, 3.32, 3.58][priceLevel]
                } else if (zhongOz <= 4) {
                    return [2.49, 3.42, 3.68][priceLevel]
                } else if (zhongOz <= 6) {
                    return [2.56, 3.45, 3.71][priceLevel]
                } else if (zhongOz <= 8) {
                    return [2.66, 3.54, 3.80][priceLevel]
                } else if (zhongOz <= 10) {
                    return [2.77, 3.68, 3.94][priceLevel]
                } else if (zhongOz <= 12) {
                    return [2.82, 3.78, 4.04][priceLevel]
                } else if (zhongOz <= 14) {
                    return [2.92, 3.91, 4.17][priceLevel]
                } else {
                    return [2.95, 3.96, 4.22][priceLevel]
                }
            } else {
                // 大号标准件
                if (zhongOz <= 4) {
                    return [2.91, 3.73, 3.99][priceLevel]
                } else if (zhongOz <= 8) {
                    return [3.13, 3.95, 4.21][priceLevel]
                } else if (zhongOz <= 12) {
                    return [3.38, 4.20, 4.46][priceLevel]
                } else if (zhongOz <= 16) {
                    return [3.78, 4.60, 4.86][priceLevel]
                } else if (zhongP <= 1.25) {
                    return [4.22, 5.04, 5.30][priceLevel]
                } else if (zhongP <= 1.5) {
                    return [4.60, 5.42, 5.68][priceLevel]
                } else if (zhongP <= 1.75) {
                    return [4.75, 5.57, 5.83][priceLevel]
                } else if (zhongP <= 2) {
                    return [5.00, 5.82, 6.08][priceLevel]
                } else if (zhongP <= 2.25) {
                    return [5.10, 5.92, 6.18][priceLevel]
                } else if (zhongP <= 2.5) {
                    return [5.28, 6.10, 6.36][priceLevel]
                } else if (zhongP <= 2.75) {
                    return [5.44, 6.26, 6.52][priceLevel]
                } else if (zhongP <= 3) {
                    return [5.85, 6.67, 6.93][priceLevel]
                } else {
                    // 上限20磅
                    return [
                        // $6.15+超出首重3磅的部分每4盎司$0.08
                        calc.add(6.15, calc.chain(zhongP).subtract(3).multiply(16).divide(4).multiply(0.08).value()),
                        // $6.97+超出首重3磅的部分每4盎司$0.08
                        calc.add(6.97, calc.chain(zhongP).subtract(3).multiply(16).divide(4).multiply(0.08).value()),
                        // $7.23+超出首重3磅的部分每4盎司$0.08
                        calc.add(7.23, calc.chain(zhongP).subtract(3).multiply(16).divide(4).multiply(0.08).value())
                    ][priceLevel]
                }
            }
        } else {
            // 2025年10月15日-2026年1月15日起  旺季
            if (size === '小号标准件') {
                // 小号标准件
                if (zhongOz <= 2) {
                    return [2.48, 3.25, 3.25][priceLevel]
                } else if (zhongOz <= 4) {
                    return [2.57, 3.34, 3.34][priceLevel]
                } else if (zhongOz <= 6) {
                    return [2.67, 3.44, 3.44][priceLevel]
                } else if (zhongOz <= 8) {
                    return [2.76, 3.53, 3.53][priceLevel]
                } else if (zhongOz <= 10) {
                    return [2.87, 3.64, 3.64][priceLevel]
                } else if (zhongOz <= 12) {
                    return [2.97, 3.74, 3.74][priceLevel]
                } else if (zhongOz <= 14) {
                    return [3.05, 3.82, 3.82][priceLevel]
                } else {
                    return [3.10, 3.87, 3.87][priceLevel]
                }
            } else {
                // 大号标准件
                if (zhongOz <= 4) {
                    return [3.15, 3.92, 3.92][priceLevel]
                } else if (zhongOz <= 8) {
                    return [3.39, 4.16, 4.16][priceLevel]
                } else if (zhongOz <= 12) {
                    return [3.66, 4.43, 4.43][priceLevel]
                } else if (zhongOz <= 16) {
                    return [4.07, 4.84, 4.84][priceLevel]
                } else if (zhongP <= 1.25) {
                    return [4.52, 5.29, 5.29][priceLevel]
                } else if (zhongP <= 1.5) {
                    return [4.91, 5.68, 5.68][priceLevel]
                } else if (zhongP <= 1.75) {
                    return [5.07, 5.84, 5.84][priceLevel]
                } else if (zhongP <= 2) {
                    return [5.00, 5.82, 6.08][priceLevel]
                } else if (zhongP <= 2.25) {
                    return [5.33, 6.10, 6.10][priceLevel]
                } else if (zhongP <= 2.5) {
                    return [5.47, 6.44, 6.44][priceLevel]
                } else if (zhongP <= 2.75) {
                    return [5.84, 6.61, 6.61][priceLevel]
                } else if (zhongP <= 3) {
                    return [6.26, 7.03, 7.03][priceLevel]
                } else {
                    // 上限20磅
                    return [
                        // $6.15+超出首重3磅的部分每4盎司$0.08
                        calc.add(6.69, calc.chain(zhongP).subtract(3).multiply(16).divide(4).multiply(0.08).value()),
                        // $6.97+超出首重3磅的部分每4盎司$0.08
                        calc.add(7.46, calc.chain(zhongP).subtract(3).multiply(16).divide(4).multiply(0.08).value()),
                        // $7.23+超出首重3磅的部分每4盎司$0.08
                        calc.add(7.46, calc.chain(zhongP).subtract(3).multiply(16).divide(4).multiply(0.08).value())
                    ][priceLevel]
                }
            }
        }
    }
    
    return {
        price: getPrice(),
        size,
    }


}